import axios from './axios';
import Vue from 'vue';
import VueScroller from 'vue-scroller';
import ls from 'store2'
// import toper from '../components/Toper';
import VueLazyload from 'vue-lazyload'

// Vue.use(toper)
Vue.use(VueScroller)
Vue.use(VueLazyload)
window.document.body.addEventListener('touchmove', function(e) {
	e.preventDefault();
}, {
	passive: false
});

var commonJs = {
	install(Vue) {
		Vue.prototype.commonJs = {
			aback: function(routerName,queryData) {
				console.log('sssss')
				let that = this
					let abc = this.funs(routerName,queryData)
				if (window.history && window.history.pushState) {
				
					history.pushState(null, null, document.URL);
					
					window.addEventListener('popstate', abc, false); //false阻止默认事件
				}
				
				

			},
			funs:function(routerName,queryData){
				
				window.$nuxt.$router.replace({
					path: routerName,
					query: {
						type: queryData
					}
				})
				console.log("监听到了222");
				
			},
			xahui:function(routerName, queryData){
				let that = this
				let abc = this.funs(routerName,queryData)
				 window.removeEventListener('popstate',abc, false);//false阻止默认事件
				
			},
			gologins: function() {
				// if (ls.get('tokens') === null || ls.get('userData') == null) {
				if (ls.get('tokens') === null) {
					window.$nuxt.$router.push('../teachers/tealogin')
					// this.commonJs.gosto('../teachers/tealogin');
					// window.$nuxt.$router.go('../teachers/tealogin')
					return;
				}
			},
			gosback: function(routerName, queryData) {
				window.$nuxt.$router.go(-1)
				// 				if (this.isTerminal() == 'isAndroid') {
				// 						window.$nuxt.$router.replace({
				// 						path: routerName,
				// 						query: {
				// 							type: queryData
				// 						}
				// 					})
				// 				} else {
				// 					window.$nuxt.$router.replace({
				// 						path: routerName,
				// 						query: {
				// 							type: queryData
				// 						}
				// 					})
				// 				}
			},
			gosto: function(routerName, queryData) {
	
					window.$nuxt.$router.replace({
						path: routerName,
						query: {
							type: queryData
						}
					})
			
			},
			isTerminal() {
				var u = navigator.userAgent;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
				var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
				if (isAndroid) {
					return "isAndroid"
				} else if (isiOS) {
					return "isiOS"
				}
			},

		};

	}

}
Vue.use(commonJs)

// document.addEventListener('DOMContentLoaded', function(){
//     if(this.$vux)this.$vux.loading.hide();
//     if(window.location.pathname!=='/web/')window.location.pathname = '/web/'
// },false); 

// let code = getParameter('code');
// if(code){
//     axios.login(code);
// }else{
//     window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8ae0aae8b40ce37e&redirect_uri=http%3A%2F%2Fwww.hengyuwy.cn&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
// }
// 登录
// axios.login('test_3');
